<template>
	<u-form :model="formData">
		<u-form-item label="位置">
			<u-input v-model="formData.reportingLocation" />
		</u-form-item>
		<u-form-item label="描述">
			<u-input v-model="formData.eventDesc" />
		</u-form-item>
		<u-form-item label="质量内容">
			<u-input v-model="value" :type="type" :border="border" @click="show = true" />
			<u-action-sheet :list="QualityList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
		</u-form-item>
		<u-form-item label="部件">
			<u-input v-model="value1" :type="type" :border="border" @click="show1 = true" />
			<u-action-sheet :list="PartsList" v-model="show1" @click="actionSheetCallback1"></u-action-sheet>
		</u-form-item>
			<u-form-item >
				<u-upload :action="action"  :auto-upload="false"  ref="uUpload" :before-upload="beforeUpload"></u-upload>
			</u-form-item>
		<u-button @click="submit">提交</u-button>
	</u-form>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				show1:false,
				value: '',
				value1:'',
				type:'select',
				QualityList:[],
				PartsList:[],
				border: true,
				formData: {
					reportingLocation: '',
					eventDesc: '',
				},
				quaIndex:[],
				parIndex:[],
				qualityId:'',
				partsId:'',
				action: 'http://139.9.169.87:9002/app/Event/addEvent',
				imgparch:'',
			};
		},
		onLoad() {
			this.getPartsListAll()
			this.getQualityListAll()
		},
		methods: {
			submit() {
				this.$refs.uUpload.upload();
				uni.uploadFile({
					url:this.action,
					filePath:this.imgparch,
					name:"file",
					method:"POST",
					formData:{
					  'reportingLocation':this.formData.reportingLocation,
					  'eventDesc':this.formData.eventDesc,
					  "reportpersonId":106,
					  'qualityId':this.qualityId,
					  'partsId':this.partsId,
					},
					success:(res)=>{
					   var data=res.data;
					   data=JSON.parse(data);
					   if(data.status==200){
					     uni.showModal({
					       content: '事件上报成功',
					       showCancel:false,
					       success:function(){
					       uni.switchTab({
					       	url:"../index/index"
					       })
					       }
					     })
					   }else{
					     uni.showModal({
					       content: '事件上报失败',
					       showCancel:false,
					       success:function(){
					       }
					     })
					   }
					},
					 fail:res=>{
					   console.log(res);
					 }
				})
			},
			beforeUpload(index,list ){
				this.imgparch=list[0].url
			},
			actionSheetCallback(index) {
				this.value = this.QualityList[index].text;
				this.qualityId=this.quaIndex[index];
			},
			actionSheetCallback1(index) {
				this.value1 = this.PartsList[index].text;
				this.partsId=this.parIndex[index];
				
			},
			getQualityListAll(){
				uni.request({
					url:'http://139.9.169.87:9002/app/Event/getQualityListAll',
					success:res=> {
						var array=res.data.data;
						
						array.forEach(item=>{
							this.QualityList.push({text:item.qualityContent})
							this.quaIndex.push(item.id)
						})
						
					}
				})
			},
			getPartsListAll(){
				uni.request({
					url:'http://139.9.169.87:9002/app/Event/getPartsListAll',
					success:res=> {
						var array=res.data.data;
						array.forEach(item=>{
							this.PartsList.push({text:item.partsName})
							this.parIndex.push(item.id)
						})
					}
				})
			}
		}
	};
</script>
